package com.meietling.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * @author LING
 * MVC处理器
 * 代替spring中的Servlet实现类，由DispatcherServlet（即中央调度器）统一调度
 */
@Controller
@RequestMapping(value = "/one")
public class OneController {

    @RequestMapping(value = "/test1.do",method = RequestMethod.GET)
    public ModelAndView test1(){
        ModelAndView view = new ModelAndView();
        view.addObject("id",1);
        view.addObject("name","xiaoA");
        view.addObject("score",85);
        view.setViewName("/test2.jsp");
        return view;
    }

    /**
     *
     * String
     */
    @RequestMapping(value = "/test2.do")
    public String test2(){
        System.out.println();
        return "/test3.jsp";
    }

    /**
     *
     * void
     */
    @RequestMapping(value = "/test3.do")
    public void test3(String userName, HttpServletResponse response) throws Exception{
        String s = new String();
        System.out.println(userName);
        //1.将异步请求对象发送的请求进行处理
        userName = "Hello"+userName;
        //2.通过响应对象将处理结果写入到响应体
        PrintWriter out = response.getWriter();
        out.print(userName);
        out.flush();
        out.close();
    }
}
